package com.yutel.amote;

import com.yutel.amote.service.AmoteConstant;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class ClientCfgActivity extends Activity implements OnClickListener {
	final String TAG = "Server";

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.clientcfg);
		EditText etIP = (EditText) findViewById(R.id.serverIP);
		AmoteConstant con=AmoteConstant.getInstance(this);
		String ip=con.getKey("serverIP");
		if(ip!=null && !"".equals(ip)){
			etIP.setText(ip);
		}
		Button btn = (Button) findViewById(R.id.appTypeOK);
		btn.setOnClickListener(this);
	}

	@Override
	public void onClick(View v) {
		EditText etIP = (EditText) findViewById(R.id.serverIP);
		EditText etPort = (EditText) findViewById(R.id.serverPort);
		Log.d(TAG, "set server port:" + etPort.getText().toString());
		AmoteConstant con=AmoteConstant.getInstance(null);
		con.save("serverIP", etIP.getText().toString());
		con.save("serverPort", etPort.getText().toString());
		Intent intent = new Intent(ClientCfgActivity.this,
				TouchActivity.class);
		startActivity(intent);
		Toast.makeText(ClientCfgActivity.this,
				"conntion server " + etIP.getText().toString() + " on port:"
						+ etPort.getText().toString(), Toast.LENGTH_SHORT)
				.show();
	}
}